package xyz.riceball.generator.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import xyz.riceball.framework.core.annotation.RbSysRequest;
import xyz.riceball.framework.core.bean.ApiController;
import xyz.riceball.framework.core.bean.ApiR;
import xyz.riceball.framework.core.bean.PageParam;
import xyz.riceball.generator.entity.po.TablePO;
import xyz.riceball.generator.service.GeneratorCodeService;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 *
 * </p>
 *
 * @author xiaovcloud
 * @since 2022/5/14 08:45
 */
@RequestMapping("/rb/api/generator")
@RestController
@RbSysRequest
@Api(tags = "代码生成")
public class GeneratorCodeController extends ApiController {

    @Resource
    private GeneratorCodeService generatorCodeService;

    @GetMapping
    @ApiOperation(value = "列表展示数据库表")
    public ApiR list(PageParam pageParam, TablePO tablePO) {
        List<TablePO> tableList = generatorCodeService.queryList(PageParam.of(pageParam), tablePO);
        return success(tableList);
    }

    @GetMapping("/code")
    @ApiOperation(value = "自动生成代码")
    public void generator(String tableNames) {
        generatorCodeService.generator(tableNames);
    }

    @GetMapping("/code/preview")
    @ApiOperation(value = "代码预览")
    public ApiR preview() {
        return success("模版预览");
    }

}
